/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author pipo
 */
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author pipo
 */
package mainGame;


import java.util.ArrayList;
import java.util.List;

public class Trainer extends GameItem{
    
    protected String name;
    protected List<Pokemon> pokemonList;

    public Trainer(int X , int Y , String name)
    {
        super(X,Y, name);
        this.pokemonList = new ArrayList<Pokemon>();
       
    }
    
    public void addPokemon(Pokemon p)
    {
        this.pokemonList.add(p);
    }
    
    public void releasePokemon(int index)
    {     
      if(index >= 0)
        this.pokemonList.remove(index);
    }
    
    public void releasePokemon(String name)
    {
        for(Pokemon p: this.pokemonList)
        {
            if(p.getName().equals(name) )
                this.pokemonList.remove(p);
        }
        
    }
    
    public boolean isAllPokemonsDead()
    {
        return this.pokemonList.isEmpty();   
    }
    
   public int pokemonCount()
   {
       
       return this.pokemonList.size();
       
   }

   public Pokemon returnPokemon(int index)
    {
        return this.pokemonList.get(index);
        
    }
   
   
    public String pokemonList()
    {
        String pList = "";
        for(int i = 0 ; i < this.pokemonCount() ; i++)
            pList += "Index: " + (i + 1) + " -> " + this.pokemonList.get(i).getProperties() + "\n";
        return pList;
        
        
    }
    
    public void refreshPokemons(int divider)
    {
        for(Pokemon t : this.pokemonList)
        {
            t.refresh(divider);
            
        }   
        
    }
    
        
    public boolean levelUp(int index)
    {
        
        boolean levelUp = false;
        Pokemon p = this.returnPokemon(index);
        if(p.getExperience() >= p.getNextLevelExperience())
        {
            p.updateAttributes(1);
            levelUp = true;
                  
        }
        
        return levelUp;
        
    }


    
}
